package com.zz.parkingsystem.controller.inspector;

import com.zz.parkingsystem.entity.Inspector;
import com.zz.parkingsystem.service.Inspector_SectionService;
import com.zz.parkingsystem.util.Result;
import com.zz.parkingsystem.util.ResultGenerator;
import com.zz.parkingsystem.vo.Inspector_SectionVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.Servlet;
import javax.servlet.http.HttpSession;
import javax.websocket.Session;
import java.util.HashMap;
import java.util.List;


/**
 * @author ：zzz
 * @date ：Created in 2022/8/30 15:42
 * @description：aaa
 */
@RestController
@RequestMapping("ins/inspe")
public class Inspector_SectionController {
    @Resource
    private Inspector_SectionService inspector_sectionService;
    //根据id查询巡查员所管理的街道
    @GetMapping("/inspe/{id}")
    public Result Inspector_Section(@PathVariable("id") Long id ,HttpSession session){
        Inspector_SectionVO inspector = inspector_sectionService.inspector_section(id);
        return ResultGenerator.genSuccessResult(inspector);
    }
    //查询街道的总车位
    @GetMapping("/getspace_count/{id}")
    public Result getspace_count(@PathVariable("id") Long id,HttpSession session){
        Long aLong = inspector_sectionService.getspace_count(id);
        return ResultGenerator.genSuccessResult(aLong);
    }
    //查询街道中生成订单中车辆为空的订单数量
    @GetMapping("/getspace_UnknownCar/{id}")
    public Result getspace_UnknownCar(@PathVariable("id") Long id,HttpSession session){
        Long car = 0l;
        List<Inspector_SectionVO> vos = inspector_sectionService.getspace_UnknownCar(id);
        for (Inspector_SectionVO vo : vos) {
            car++;
        }
        return ResultGenerator.genSuccessResult(car);
    }
    //查询巡检员订单完成率
    @GetMapping("/getOrderCompletionRate/{id}")
    public Result getOrderCompletionRate(@PathVariable("id") Long id,HttpSession session){
        List getorder = inspector_sectionService.getorder(id);
        //异常订单
        List getexcOrder = inspector_sectionService.getexcOrder(id);

        int size = getorder.size();
        float torder= size;
        int size1 = getexcOrder.size();
        float excOrder=size1;
        String bb = "";
        float lo = (torder - excOrder) / torder;
       String aa = lo+"";
       if (aa != "1.00"){
            bb = aa.substring(2)+"%";
       }else{
           bb = aa.substring(0, 1)+"%";
       }

        System.out.println(bb+"11111111111111111111111111");
        return ResultGenerator.genSuccessResult(bb);
    }
    //停车拍照
    //查询没有车牌的订单，巡检员》街道》车位》订单》开始时间
    @GetMapping("/getpark_photograph/{id}")
    public Result getpark_photograph(@PathVariable("id") Long id, HttpSession session){
        List<Inspector_SectionVO> inspector_sectionVOS = inspector_sectionService.getpark_photograph(id);

//        HashMap<Object, Object> map = new HashMap<>();
//        for (Inspector_SectionVO inspector_sectionVO : inspector_sectionVOS) {
//            if ((long)(inspector_sectionVO.getInsId()) == id){
//                map.put("inspector_sectionVO",inspector_sectionVO);
//                System.out.println(inspector_sectionVO);
//            }
//        }
        return ResultGenerator.genSuccessResult(inspector_sectionVOS);
    }
}
